package com.cqc.googleplay.view.part;

import java.util.ArrayList;

import com.cqc.googleplay.R;
import com.cqc.googleplay.activity.ImageScalActivity;
import com.cqc.googleplay.application.ImageLoaderOptions;
import com.cqc.googleplay.application.MyApplication;
import com.cqc.googleplay.bean.AppInfoBean;
import com.cqc.googleplay.http.NetUrl;
import com.cqc.googleplay.utils.CommonUtil;
import com.nostra13.universalimageloader.core.ImageLoader;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.sax.StartElementListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewDebug.FlagToString;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class AppInfoScreenPart {
	private Context context;
	private View part3View;
	private LinearLayout ll_part3;
	private int marginLeft;
	private int ivWidth;
	private int ivHeight;
	private ArrayList<String> screenList;

	public AppInfoScreenPart() {
		super();
		context = MyApplication.getContext();
		marginLeft = (int) CommonUtil.getDimension(R.dimen.part3_iv_margin_left);
		ivWidth = (int) CommonUtil.getDimension(R.dimen.part3_iv_width);
		ivHeight = (int) CommonUtil.getDimension(R.dimen.part3_iv_height);
	}
	
	public View getView() {
		part3View = View.inflate(context, R.layout.part3_app_screen,null);
		ll_part3 = (LinearLayout) part3View.findViewById(R.id.ll_part3);
		return part3View;
	}

	public void setData(AppInfoBean info) {
		screenList = info.getScreen();
		for (int i = 0; i < screenList.size(); i++) {
			ImageView iv = new ImageView(context);
//			LayoutParams params = new LayoutParams(150, 300);//直接写数字是像素，不是dp
			LayoutParams params = new LayoutParams(ivWidth,ivHeight);
			if (i > 0) {
				params.leftMargin = marginLeft;
			}
			iv.setLayoutParams(params);
			ImageLoader.getInstance().displayImage(NetUrl.IMAGE_PREFIX + screenList.get(i), iv, ImageLoaderOptions.pagerOptions);
			
			ll_part3.addView(iv);
			
			final int currentPager = i;
			iv.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent intent = new Intent(context, ImageScalActivity.class);
					intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					intent.putStringArrayListExtra("screenList", screenList);
					intent.putExtra("currentPager", currentPager);
					context.startActivity(intent);
				}
			});
		}
	}
}
